local caijue = fk.CreateSkill {
  name = "th_caijue",
}

caijue:addEffect(fk.Damage, {
  anim_type = "offensive",
  can_trigger = function(self, event, target, player, data)
    return target and target ~= player and player:hasSkill(caijue.name) and data.to and player:compareDistance(data.to, 1, "<=")
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if not target.dead then room:doIndicate(player.id, {target.id}) end
    local judge = {
      who = target,
      reason = caijue.name,
      pattern = {
        [".|.|black,red"] = "good",
        [".|.|red"] = "red",
        [".|.|black"] = "black",
        ["else"] = "bad",
      },
    }
    room:judge(judge)
    if not judge.results then return false end
    if table.contains(judge.results, "black") and not target.dead then
      room:damage{
        from = nil,
        to = target,
        damage = 1,
        skillName = caijue.name,
      }
    elseif table.contains(judge.results, "red") and not target:isNude() then
      local cid = room:askToChooseCard(player, {
        target = target,
        flag = "he",
        skill_name = caijue.name
      })
      room:throwCard({cid}, caijue.name, target, player)
    end
  end
})

Fk:loadTranslationTable{
  ["th_caijue"] = "裁决",
  [":th_caijue"] = "其他角色对你距离不大于1的角色造成伤害后，你可以令其判定，若为：黑色，其受到1点伤害；红色，你弃置其一张牌。",
}

return caijue